* Change to working directory *
use "KK_NMS_replication.dta", clear
* Get total number of issue emails sent -- *
tab humanorai
* Get number of state legislators who received these emails *
collapse (sum) humanorai, by(legislator_id)
sum 

use "KK_NMS_replication.dta", clear

* Figure 2: Response Rates, human vs. AI *
ciplot response, by(category) symbol(circle) color(black) ylabel(.20 "20%" .18 "18%" .16 "16%" .14 "14%" .12 "12%".1 "10%") yti("Response rate" " ") xti("") note("") graphregion(color(white))
ttest response if humanorai==1, by(ai)

* Figure 3: Response Rates, human vs. AI *
use "KK_NMS_replication.dta", clear

gen n = _n
gen diff = .
gen l = .
gen u = .
gen sediff = .
gen treatment = .
gen group = .


ttest response if topic_guns == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 1
replace sediff = r(se) if n == 1
replace treatment = 1 if n == 1

ttest response if topic_health == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 2
replace sediff = r(se) if n == 2
replace treatment = 2 if n == 2

ttest response if topic_policing == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 3
replace sediff = r(se) if n == 3
replace treatment = 3 if n == 3

ttest response if topic_reproductive == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 4
replace sediff = r(se) if n == 4
replace treatment = 4 if n == 4

ttest response if topic_schools == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 5
replace sediff = r(se) if n == 5
replace treatment = 5 if n == 5

ttest response if topic_taxes == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 6
replace sediff = r(se) if n == 6
replace treatment = 6 if n == 6

label define topics 1 "Guns" 2 "Health" 3 "Policing" 4 "Reproductive" 5 "Schools" 6 "Taxes"
label values treatment topics

replace l = diff-1.96*(sediff)
replace u = diff+1.96*(sediff)


gen x = _n
recode x  (6=1) (5=2) (4=3) (3=4) (2=5) (1=6)
replace x = . if x>6

twoway (dot  diff x, horizontal ndots(0) dcolor(white) symbol(circle) color(black)) ///
(rcap u l x, horizontal color(black)), yti("") graphregion(color(white)) ///
xlabel(-.06 "-6%" -.04 "-4%" -.02 "-2%" 0 "0%" .02 "2%" .04 "4%") xline(0) ///
ylabel( 6 "Guns" 5 "Health" 4 "Policing" 3 "Reproductive rights" 2 "Schools" 1 "Taxes", angle(0)) /// 
ti("") saving(fig2.gph, replace) legend(off)

* Figure 4: Length of responses by Human or AI on issues *
use "KK_NMS_replication.dta", clear
graph box nwords_email if response == 1, by(category) graphregion(color(white)) nooutsides graphregion(color(white)) yti("# Words" " ") ti("")  note("")
ranksum nwords_email if response == 1, by(ai)
median nwords_email if response == 1, by(ai)
* medians and IQ ranges *
sum nwords_email if ai == 0, detail
sum nwords_email if ai == 1, detail

* Table 1: Partisan-ideological congruence *
use "/Users/dlk265/Library/CloudStorage/Box-Box/Atkinson Projects/AI_state_leg/data/KK_NMS_replication.dta", clear
gen aixconservative = ai*conservative
label var ai "GPT-3"
label var conservative "Conseravtive slant"
label var aixconservative "GPT-3 X Conservative"
label var topic_health "Topic: Health"
label var topic_policing "Topic: Policing"
label var topic_reproductive "Topic: Reproductive"
label var topic_schools "Topic: Schools"
label var topic_taxes "Topic: Taxes"

logit response ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using table1, word dec(2) label replace
logit response ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using table1, word dec(2) label append
logit response ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using table1, word dec(2) label append
logit response ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using table1, word dec(2) label append

* SUPPORTING INFORMATION *

* SI Figure 1: Response Rates excluding auto-replies and requests for more information *
use "KK_NMS_replication.dta", clear

ciplot response_dropauto, by(category) symbol(circle) color(black) ylabel(.12 "12%".1 "10%" .08 "8%" .06 "6%" .04 "4%" .02 "2%" 0 "0%") yti("Response rate" " ") xti("") ti("Excludes auto-replies") note("") graphregion(color(white)) saving(sifig1a.gph, replace)
ciplot response_dropauto_check, by(category) symbol(circle) color(black) ylabel(.12 "12%".1 "10%" .08 "8%" .06 "6%" .04 "4%" .02 "2%" 0 "0%") yti("Response rate" " ") ti("Excludes auto-replies and requests for more info") xti("") note("") graphregion(color(white)) saving(sifig1b.gph, replace)
graph combine sifig1a.gph sifig1b.gph, graphregion(color(white)) rows(2) xsize(8.5) ysize(11)

* Non-auto reply requests for more information: more common in GPT-3 emails? *
* Look only at cases where there was no substantive reply or an auto-reply;hence outcomes 3 and 4 *
ttest request_info_not_auto if outcome == 3|outcome==4, by(category)

* SI Figure 2 *
use "KK_NMS_replication.dta", clear
* top panel *
gen n = _n
gen diff = .
gen l = .
gen u = .
gen sediff = .
gen treatment = .
gen group = .

ttest response_dropauto if topic_guns == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 1
replace sediff = r(se) if n == 1
replace treatment = 1 if n == 1

ttest response_dropauto if topic_health == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 2
replace sediff = r(se) if n == 2
replace treatment = 2 if n == 2

ttest response_dropauto if topic_policing == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 3
replace sediff = r(se) if n == 3
replace treatment = 3 if n == 3

ttest response_dropauto if topic_reproductive == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 4
replace sediff = r(se) if n == 4
replace treatment = 4 if n == 4

ttest response_dropauto if topic_schools == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 5
replace sediff = r(se) if n == 5
replace treatment = 5 if n == 5

ttest response_dropauto if topic_taxes == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 6
replace sediff = r(se) if n == 6
replace treatment = 6 if n == 6

label define topics 1 "Guns" 2 "Health" 3 "Policing" 4 "Reproductive" 5 "Schools" 6 "Taxes"
label values treatment topics

replace l = diff-1.96*(sediff)
replace u = diff+1.96*(sediff)

gen x = _n
recode x  (6=1) (5=2) (4=3) (3=4) (2=5) (1=6)
replace x = . if x>6

twoway (dot  diff x, horizontal ndots(0) dcolor(white) symbol(circle) color(black)) ///
(rcap u l x, horizontal color(black)), yti("") graphregion(color(white)) ///
xlabel(-.06 "-6%" -.04 "-4%" -.02 "-2%" 0 "0%" .02 "2%" .04 "4%") xline(0) ///
ylabel( 6 "Guns" 5 "Health" 4 "Policing" 3 "Reproductive rights" 2 "Schools" 1 "Taxes", angle(0)) /// 
ti("Excludes auto-replies", size(medsmall)) saving(sifig2a.gph, replace) legend(off)

* Bottom panel *
use "/Users/dlk265/Library/CloudStorage/Box-Box/Atkinson Projects/AI_state_leg/data/KK_NMS_replication.dta", clear

gen n = _n
gen diff = .
gen l = .
gen u = .
gen sediff = .
gen treatment = .
gen group = .

ttest response_dropauto_check if topic_guns == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 1
replace sediff = r(se) if n == 1
replace treatment = 1 if n == 1

ttest response_dropauto_check if topic_health == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 2
replace sediff = r(se) if n == 2
replace treatment = 2 if n == 2

ttest response_dropauto_check if topic_policing == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 3
replace sediff = r(se) if n == 3
replace treatment = 3 if n == 3

ttest response_dropauto_check if topic_reproductive == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 4
replace sediff = r(se) if n == 4
replace treatment = 4 if n == 4

ttest response_dropauto_check if topic_schools == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 5
replace sediff = r(se) if n == 5
replace treatment = 5 if n == 5

ttest response_dropauto_check if topic_taxes == 1, by(ai)
replace diff = r(mu_2)-r(mu_1) if n == 6
replace sediff = r(se) if n == 6
replace treatment = 6 if n == 6

label define topics 1 "Guns" 2 "Health" 3 "Policing" 4 "Reproductive" 5 "Schools" 6 "Taxes"
label values treatment topics

replace l = diff-1.96*(sediff)
replace u = diff+1.96*(sediff)

gen x = _n
recode x  (6=1) (5=2) (4=3) (3=4) (2=5) (1=6)
replace x = . if x>6

twoway (dot  diff x, horizontal ndots(0) dcolor(white) symbol(circle) color(black)) ///
(rcap u l x, horizontal color(black)), yti("") graphregion(color(white)) ///
xlabel(-.06 "-6%" -.04 "-4%" -.02 "-2%" 0 "0%" .02 "2%" .04 "4%") xline(0) ///
ylabel( 6 "Guns" 5 "Health" 4 "Policing" 3 "Reproductive rights" 2 "Schools" 1 "Taxes", angle(0)) /// 
ti("Excludes auto-replies and requests for more info", size(medsmall)) saving(sifig2b.gph, replace) legend(off)
graph combine sifig2a.gph sifig2b.gph, graphregion(color(white)) rows(2) xsize(8.5) ysize(11)

** SI Figure 3: Length with two alternate operationalizations of response *
graph box nwords_email if response_dropauto == 1, by(category, note("") graphregion(color(white))) nooutsides graphregion(color(white)) yti("# Words" " ")  note("") ti("") saving(sifig3a.gph, replace)
ranksum nwords_email if response == 1, by(ai)
median nwords_email if response == 1, by(ai)
graph box nwords_email if response_dropauto_check == 1, by(category, note("") graphregion(color(white))) nooutsides graphregion(color(white)) yti("# Words" " ") ti("Excludes auto-replies and requests for more info") note("") saving(sifig3b.gph, replace)
ranksum nwords_email if humanorai==1 & response_noauto == 1, by(ai)
median nwords_email if humanorai==1 & response_noauto == 1, by(ai)
graph combine sifig3a.gph sifig3b.gph, graphregion(color(white)) rows(2) xsize(8.5) ysize(12)

* Test Moderating Hypotheses *

* SI Table 1: Exclude auto-replies and Exclude auto-replies and requests for more information *
use "KK_NMS_replication.dta", clear
gen aixconservative = ai*conservative
label var ai "GPT-3"
label var conservative "Conseravtive slant"
label var aixconservative "GPT-3 X Conservative"
label var topic_health "Topic: Health"
label var topic_policing "Topic: Policing"
label var topic_reproductive "Topic: Reproductive"
label var topic_schools "Topic: Schools"
label var topic_taxes "Topic: Taxes"

logit response_dropauto ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label replace
logit response_dropauto ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append
logit response_dropauto ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append
logit response_dropauto ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append

logit response_dropauto_check ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append
logit response_dropauto_check ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append
logit response_dropauto_check ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append
logit response_dropauto_check ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1, cluster(legislator_id)
outreg2 using sitable1, word dec(2) label append

* SI Table 2: Main analyses with only significant issues *
gen sigdif = 0
replace sigdif = 1 if topic_policing == 1
replace sigdif = 1 if topic_reproductive == 1
replace sigdif = 1 if topic_taxes == 1

logit response ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable2, word dec(2) label replace
logit response ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable2, word dec(2) label append
logit response ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable2, word dec(2) label append
logit response ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable2, word dec(2) label append

* SI Table 3: Only Significant Issues, Alternate Operationalizations of Resposne *
logit response_dropauto ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label replace
logit response_dropauto ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append
logit response_dropauto ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append
logit response_dropauto ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append

logit response_dropauto_check ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append
logit response_dropauto_check ai  conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append
logit response_dropauto_check ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if demleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append
logit response_dropauto_check ai aixconservative conservative  topic_health topic_policing topic_reproductive topic_schools topic_taxes if gopleg == 1 & sigdif == 1, cluster(legislator_id)
outreg2 using sitable3, word dec(2) label append

* Are requests for more information more common for GPT-3 produced emails than human-generated emails ? *
ttest request_info_not_auto, by(category)
